import fetch from 'common/src/utils/fetch';

/**
 * 查询教师列表信息
 */
export function findTeacherList(data) {
    return fetch({
        url: '/api/baseresservice/teacher/findTeacherList',
        method: 'post',
        data
    });
}

/**
 * 批量更新教师信息（手机号、邮箱）
 * @param data
 */
export function batchEditTeachers(data) {
  return fetch({
    url: '/api/baseresservice/teacher/batchEditTeachers',
    method: 'PUT',
    data
  });
}

/**
 * 教学进度指定审批教师(列表查询)
 * @param data
 */
export function progressTeacherList(data) {
    return fetch({
        url: '/api/baseresservice/teacher/progressTeacherList',
        method: 'post',
        data
    });
}

/**
 * 导出教师信息对应的excel文件
 * @param {Object} params
 */
export function exportTeacherList(params) {
    let url = '/api/baseresservice/teacher/exportTeacherList';
    let remove_params = ['pageNum_', 'pageSize_', 'total'];
    let queryParam = '';
    for (let key in params) {
    // 去掉分页
        if (remove_params.includes(key)) {
            continue;
        }
        // 去掉空参数
        if (params[key] == '') {
            continue;
        }
        queryParam += `${key}=${params[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}

/**
 * 提交教师授权审批
 * @param data
 */
export function checkTeacherAuth(data) {
    return fetch({
        url: '/api/baseresservice/teacher/checkTeacherAuth',
        method: 'post',
        data
    });
}

/**
 * 查询职称审批状态列表
 * @param data
 */
export function getTeacherTitleList(data) {
    return fetch({
        url: '/api/baseresservice/teacherTitle/findTeacherTitleList',
        method: 'post',
        data
    });
}

/**
 * 批量修改审批状态信息(需要审批)
 * @param data
 */
export function updateNeedTeacherTitle(data) {
    return fetch({
        url: '/api/baseresservice/teacherTitle/batchNeedTeacherTitle',
        method: 'put',
        data
    });
}

/**
 * 批量修改审批状态信息(不需要审批)
 * @param data
 */
export function updateNoNeedTeacherTitle(data) {
    return fetch({
        url: '/api/baseresservice/teacherTitle/batchNoNeedTeacherTitle',
        method: 'put',
        data
    });
}

/**
 * 教师批量授权(不需要审批)
 * @param data
 */
export function batchUpdApprovalStatus(data) {
    return fetch({
        url: '/api/baseresservice/teacher/batchUpdApprovalStatus',
        method: 'put',
        data
    });
}
/**
 * 查询教师列表
 * {
	"faculty":faculty（字符串）,
	"name":name(可要可不要)
}
 * @param {*} data
 */
export function findListByFaculty(data) {
    return fetch({
        url: 'api/baseresservice/teacher/findList?condition=' + data,
        method: 'post'
    });
}
/**
 * 新增教师
 * @param {} data
 */
export function addTeacher(data) {
    return fetch({
        url: 'api/baseresservice/teacher',
        method: 'post',
        data
    });
}
/**
 * 删除教师
 * @param {} data
 */
export function deleteTeacher(data) {
    return fetch({
        url: 'api/baseresservice/teacher',
        method: 'DELETE',
        data
    });
}
/**
 * 查询教师根据id
 * @param {} data
 */
export function findTeacherById(id) {
    return fetch({
        url: 'api/baseresservice/teacher/findTeacherById?id=' + id,
        method: 'GET'
    });
}


/**
 * 查询教师根据id
 * @param {} data
 */
export function findTeacherBycode(code) {
    return fetch({
        url: 'api/baseresservice/teacher/findTeacherBycode?code=' + code,
        method: 'GET'
    });
}
/**
 * 查询教师根据id
 * @param {} data
 */
export function findRawTeacherById(id) {
    return fetch({
        url: 'api/baseresservice/teacher/' + id,
        method: 'GET'
    });
}


/**
 * 更新教师根据id
 * @param {} data
 */
export function updateTeacher(data) {
    return fetch({
        url: 'api/baseresservice/teacher',
        method: 'PUT',
        data
    });
}
/**
 * 更新校外教师状态
 * @param {} data
 */
export function updateTeacherStatus(data) {
    return fetch({
        url: 'api/baseresservice/teacher/status',
        method: 'PUT',
        data
    });
}
/**
 * 按学院统计职称人员
 * @param {} data
 */
export function statisticsTitle(data) {
    return fetch({
        url: 'api/baseresservice/teacher/title',
        method: 'POST',
        data
    });
}
/**
 * 设置授课时间，申报时间
 * @param {} data
 */
export function setTime(data) {
    return fetch({
        url: 'api/baseresservice/teacher/time/up',
        method: 'POST',
        data
    });
}
/**
 * 取申报时间
 * @param {} data
 */
export function getTime(data) {
    return fetch({
        url: 'api/baseresservice/teacher/time',
        method: 'POST',
        data
    });
}
/**
 * 上传申请模板
 * @param {} data
 */
export function uploadApplyFile(path) {
    return fetch({
        url: 'api/baseresservice/teacher/template/upload?path=' + path,
        method: 'POST'
    });
}
/**
 * 上传申请模板
 * @param {} data
 */
export function getApplyFile() {
    return fetch({
        url: 'api/baseresservice/teacher/template/path',
        method: 'GET'
    });
}
/**
 * 设置授课资格
 * @param {} data
 */
export function setQualification(data) {
    return fetch({
        url: 'api/baseresservice/teacher/teachQual',
        method: 'PUT',
        data
    });
}
/**
 * 下拉查询教师列表（申请授课资格使用）
 * @param {} data
 */
export function qualificationList(condition) {
    return fetch({
        url: 'api/baseresservice/teacher/list?condition=' + condition,
        method: 'POST'
    });
}
/**
 * 查询教师资格申请列表
 * @param {} data
 */
export function getQualificationList(data) {
    return fetch({
        url: 'api/baseresservice/teacher/apply/list',
        method: 'POST',
        data
    });
}
/**
 *教师授课资格申请
 * @param {} data
 */
export function applyQualification(data) {
    return fetch({
        url: 'api/baseresservice/teacher/checkTeacherAuth',
        method: 'POST',
        data
    });
}
/**
 * 教师资格审核列表
 * @param {} data
 */
export function approvalList(data) {
    return fetch({
        url: 'api/baseresservice/teacher/approval/list',
        method: 'POST',
        data
    });
}
/**
 * 批量设置试听计划
 * @param {} data
 */
export function setTryListen(data) {
    return fetch({
        url: 'api/baseresservice/teacher',
        method: 'PUT',
        data
    });
}

/**
 * 导出在职人数统计
 * @param {*} params
 */
export function exportTitle(data) {
    let url = 'api/baseresservice/teacher/title/export';
    let fileName = 'teacherTitle.xls';
    downloadFile(data, url, fileName);
}
/**
 * 统计各职称人数详情
 * @param {*} params
 */
export function exportFacultyTitle(data) {
    let url = 'api/baseresservice/teacher/title/faculty/export';
    let fileName = 'teacherTitleDetail.xls';
    downloadFile(data, url, fileName);
}
/**
 * 教师导出
 * @param {*} params
 */
export function exportTeacher(data) {
    return fetch({
        url: 'api/baseresservice/teacher/exportTeacherList',
        method: 'post',
        data,
        showMask: false
    });
}
/**
 * 教师导出
 * @param {*} params
 */
export function getReportStatus(key) {
    return fetch({
        url: 'api/baseresservice/teacher/result/' + key,
        method: 'get'
    });
}

/**
 * 导出审批教师列表
 * @param {*} params
 */
export function exportApproveTeacher(data) {
    let url = 'api/baseresservice/teacher/approval/export';
    let fileName = 'teacherApproval.xls';
    downloadFile(data, url, fileName);
}

function downloadFile(data, url, fileName) {
    fetch({
        url: url,
        method: 'POST',
        data,
        responseType: 'blob'
    }).then(resp => {
        if (!resp) {
            return;
        }
        if (window.navigator && window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveOrOpenBlob(new Blob([resp]), fileName);
        } else {
            let url = window.URL.createObjectURL(new Blob([resp]));
            let link = document.createElement('a');
            link.style.display = 'none';
            link.href = url;
            link.setAttribute('download', fileName);
            document.body.appendChild(link);
            link.click();
        }
    });
}
/**
 *     查询所属管理部门下全量学院列表
 * @param {*} deptId
 */
export function getAllFaculty(deptId = 1) {
    return fetch({
        url: `/api/userservice/dept/findDept?virtualDept=0&type=1&manageDept=${deptId}`,
        method: 'GET'
    });
}

/**
 *     导出授课资格操作记录
 *
 */
export function exportOperate(data) {
    let url = '/api/baseresservice/teacher/exportOperate';
    let fileName = 'teachQualRecord.xls';
    downloadFile(data, url, fileName);
}


/**
 *  查询用户权限内的学科专业委员会列表
 */
export function getSubjectMajorByUser(data) {
    return fetch({
        url: '/api/baseresservice/teacher/getSubjectMajorByUser',
        method: 'POST',
        data
    });
}

/**
 *  根据学科专业委员会查询其所包含角色
 */
export function getSubjectMajorRole(subjectMajorCode) {
    return fetch({
        url: '/api/baseresservice/teacher/subjectMajorRole/' + subjectMajorCode,
        method: 'GET'
    });
}

export function editApprovalStatus(id) {
    return fetch({
        url: '/api/baseresservice/teacher/editApprovalStatus?id=' + id,
        method: 'PUT'
    });
}
